#include "stdafx.h"
#include "../Inc/vector.h"
#include <math.h>

mlVector2D::mlVector2D()
{

}

mlVector2D::mlVector2D(float _x, float _y):x(_x),y(_y)
{

}

float mlVector2D::length()
{
	return sqrt(x*x+y*y);
}

void mlVector2D::normalize()
{
	float len = sqrt(x*x + y*y);
	if (len > 0)
	{
		x /= len;
		y /= len;
	}
}

mlVector2D& mlVector2D::operator+(const mlVector2D& a) const
{
	return mlVector2D(x+a.x, y+a.y);
}

mlVector2D& mlVector2D::operator-(const mlVector2D& a) const
{
	return mlVector2D(x-a.x, y-a.y);
}

mlVector2D& mlVector2D::operator+=(const mlVector2D& a)
{
	x += a.x;
	y += a.y;
	return *this;
}

mlVector2D& mlVector2D::operator-=(const mlVector2D& a)
{
	x -= a.x;
	y -= a.y;
	return *this;
}

mlVector2D& mlVector2D::operator*(float a) const
{
	return mlVector2D(x*a, y*a);
}

mlVector2D& mlVector2D::operator/(float a) const
{
	return mlVector2D(x/a, y/a);
}

mlVector2D& mlVector2D::operator*=(float a)
{
	x *= a;
	y *= a;
	return *this;
}

mlVector2D& mlVector2D::operator/=(float a)
{
	x /= a;
	y /= a;
	return *this;
}

float mlVector2D::operator*(const mlVector2D& a) const
{
	return (x*a.x + y*a.y);
}

mlVector3D::mlVector3D()
{

}

mlVector3D::mlVector3D(float _x, float _y, float _z):x(_x),y(_y),z(_z)
{

}

float mlVector3D::length()
{
	return sqrt(x*x+y*y+z*z);
}

void mlVector3D::normalize()
{
	float len = sqrt(x*x + y*y + z*z);
	if (len > 0)
	{
		x /= len;
		y /= len;
		z /= len;
	}
}

mlVector3D& mlVector3D::operator+(const mlVector3D& a) const
{
	return mlVector3D(x+a.x, y+a.y, z+a.z);
}

mlVector3D& mlVector3D::operator-(const mlVector3D& a) const
{
	return mlVector3D(x-a.x, y-a.y, z-a.z);
}

mlVector3D& mlVector3D::operator+=(const mlVector3D& a)
{
	x += a.x;
	y += a.y;
	z += a.z;
	return *this;
}

mlVector3D& mlVector3D::operator-=(const mlVector3D& a)
{
	x -= a.x;
	y -= a.y;
	z -= a.z;
	return *this;
}

mlVector3D& mlVector3D::operator*(float a) const
{
	return mlVector3D(x*a, y*a, z*a);
}

mlVector3D& mlVector3D::operator/(float a) const
{
	return mlVector3D(x/a, y/a, z/a);
}

mlVector3D& mlVector3D::operator*=(float a)
{
	x *= a;
	y *= a;
	z *= a;
	return *this;
}

mlVector3D& mlVector3D::operator/=(float a)
{
	x /= a;
	y /= a;
	z /= a;
	return *this;
}

float mlVector3D::operator*(const mlVector3D& a) const
{
	return (x*a.x + y*a.y + z*a.z);
}

inline mlVector3D& crossProduct(const mlVector3D&a ,const mlVector3D& b)
{
	return mlVector3D(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
}